﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph; // important!! ADD this!!
using LimitedScopeTrader.Business;
using LimitedScopeTrader.Data;
using LimitedScopeTrader.Data.StocksDataSetTableAdapters;

namespace LimitedScopeTrader
{
    public partial class frmChartx : Form
    {
        private LimitedScopeBusiness businessLayer;
        public frmChartx()
        {
            InitializeComponent();

            this.businessLayer = new LimitedScopeBusiness() ;
            List<string> securities = (from tickers in businessLayer.GetSecurities()
                                       select tickers.Ticker).ToList();

            this.cmbTicker.DataSource = securities;
        }

        private void frmChart_Load(object sender, EventArgs e)  // initial chart 
        {
            zedGraphControl1.GraphPane.Title.Text = "Status"; //title
            zedGraphControl1.GraphPane.XAxis.Title.Text = "Time"; //X-axis name
            zedGraphControl1.GraphPane.YAxis.Title.Text = "Price"; //Y-axis name

        }

        /// <summary>
        /// Button click event handler to close the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnGetData_Click(object sender, EventArgs e)
        {
            GraphPane myPane = zedGraphControl1.GraphPane;
            zedGraphControl1.GraphPane.CurveList.Clear();//clear the previous chart

            string[] xTitle = { "2007/8/1", "2007/8/2", "2007/8/3", "2007/8/4" }; //X-axis data

            double[] NB = { 61, 64, 69, 75 };//NB price = Y-axis

            LineItem myCurve;

            #region line
            myCurve = myPane.AddCurve("NB", null, NB, Color.Purple);  // curve( name, X , Y, color), X will add "2 lines after"
            myCurve.Line.Fill = new Fill();

            #endregion

            myPane.XAxis.Scale.TextLabels = xTitle; // add X;
            myPane.XAxis.Type = AxisType.Text;
            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));
            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            zedGraphControl1.GraphPane.CurveList.Clear();//clear the previous chart

            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }

    }
}
